#!/bin/bash
#!/bin/expect

token=dd5ab5203cb26b07560f269355c4c9ec
gitee_id=wangchong1995924

curl -X POST --header 'Content-Type: application/json;charset=UTF-8' "https://gitee.com/api/v5/repos/src-openEuler/$1/forks" -d "{\"access_token\":\"$token\"}" &>/dev/null && echo "fork yes"                     
#echo -n "ready to clone ? (y/n) "                     
#read to_clone                     
#if [ $to_clone == "y" ];then                     
	git clone https://gitee.com/${gitee_id}/$1.git
#else                     
#	echo 'The Program is exit...'                   
#	exit 1                     
#fi                     
cd $1 && git pull
yumdownloader --source $1
rpm2cpio *.rpm | cpio -dim
rm -f *.rpm
bash /root/spec_prep.sh $1.spec
rm $1.spec~ -f
vim $1.spec
cp /root/mb.yaml $1.yaml
vim $1.yaml
git add -A
git status
git commit -m "package init"
echo 'Are you ready to push ?(y/n)'
read choose
if [ $choose == 'y' ];then
	expect -c "
	spawn git push
	expect {
	\"*Username*\" {send \"wangchong1995924\r\";exp_continue}
	\"*Password*\" {send \"Huawei12#$\r\";exp_continue}
	}
	"
else
	echo "You can check it again,then git push to gitee by yourself!"
fi
echo -n "read to pr ?(y/n)"
read do_pr
if [ $do_pr == 'y' ];then
	curl -X POST --header 'Content-Type: application/json;charset=UTF-8' "https://gitee.com/api/v5/repos/src-openeuler/$1/pulls" -d "{\"access_token\":\"$token\",\"title\":\"package init \",\"head\":\"$gitee_id:master\",\"base\":\"master\"}" &>/dev/null && echo "PR yes"
else
	echo "You can do pr with yourself in gitee.com!"
fi
